]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell/network-agent: Wrap nm_plugin_info_new_search_file()
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 14 Mar 2020 20:51:33 +0000 (21:51 +0100)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 17 Mar 2020 14:07:15 +0000 (14:07 +0000)
While we can use the libnm API directly from JS, the call will
synchronously load the VPN service descriptions from disk.
Previously we were lowering the impact by caching the result,
but as we stopped doing that, it becomes more important to address
the issue properly and move it off to a thread.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/2386

src/shell-network-agent.c
src/shell-network-agent.h

index 8e1f82017bbf52d6d41c3fe66b3ece3b66ca9463..4fab298e5a66d0e6128ce836feaf51103c497178 100644 (file)
@@ -478,6 +478,63 @@ shell_network_agent_respond (ShellNetworkAgent         *self,
   g_hash_table_remove (priv->requests, request_id);
 }
 
+static void
+search_vpn_plugin (GTask        *task,
+                   gpointer      object,
+                   gpointer      task_data,
+                   GCancellable *cancellable)
+{
+  NMVpnPluginInfo *info = NULL;
+  char *service = task_data;
+
+  info = nm_vpn_plugin_info_new_search_file (NULL, service);
+
+  if (info)
+    {
+      g_task_return_pointer (task, info, g_object_unref);
+    }
+  else
+    {
+      g_task_return_new_error (task,
+                               G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                               "No plugin for %s", service);
+    }
+}
+
+void
+shell_network_agent_search_vpn_plugin (ShellNetworkAgent   *self,
+                                       const char          *service,
+                                       GAsyncReadyCallback  callback,
+                                       gpointer             user_data)
+{
+  g_autoptr(GTask) task = NULL;
+
+  g_return_if_fail (SHELL_IS_NETWORK_AGENT (self));
+  g_return_if_fail (service != NULL);
+
+  task = g_task_new (self, NULL, callback, user_data);
+  g_task_set_source_tag (task, shell_network_agent_search_vpn_plugin);
+  g_task_set_task_data (task, g_strdup (service), g_free);
+
+  g_task_run_in_thread (task, search_vpn_plugin);
+}
+
+/**
+ * shell_network_agent_search_vpn_plugin_finish:
+ *
+ * Returns: (nullable) (transfer full): The found plugin or %NULL
+ */
+NMVpnPluginInfo *
+shell_network_agent_search_vpn_plugin_finish (ShellNetworkAgent  *self,
+                                              GAsyncResult       *result,
+                                              GError            **error)
+{
+  g_return_val_if_fail (SHELL_IS_NETWORK_AGENT (self), NULL);
+  g_return_val_if_fail (G_IS_TASK (result), NULL);
+
+  return g_task_propagate_pointer (G_TASK (result), error);
+}
+
 static void
 shell_network_agent_cancel_get_secrets (NMSecretAgentOld *agent,
                                         const gchar      *connection_path,
index 73dfe5b1d02c3d8c033e43a58ae8b0d29c66c2dd..e01b368f0ddbdcd49cc3bea77d05b7290b5442e5 100644 (file)
@@ -51,6 +51,14 @@ void               shell_network_agent_respond      (ShellNetworkAgent *self,
                                                      gchar             *request_id,
                                                      ShellNetworkAgentResponse response);
 
+void               shell_network_agent_search_vpn_plugin (ShellNetworkAgent   *self,
+                                                          const char          *service,
+                                                          GAsyncReadyCallback  callback,
+                                                          gpointer             user_data);
+NMVpnPluginInfo   *shell_network_agent_search_vpn_plugin_finish (ShellNetworkAgent  *self,
+                                                                 GAsyncResult       *result,
+                                                                 GError            **error);
+
 /* If these are kept in sync with nm-applet, secrets will be shared */
 #define SHELL_KEYRING_UUID_TAG "connection-uuid"
 #define SHELL_KEYRING_SN_TAG "setting-name"